package com.apobates.jforum2.troll.accounts.mapper;

import com.apobates.jforum2.troll.accounts.entity.MemberActiveRecords;
import com.apobates.jforum2.troll.accounts.stub.vo.MemberRecordVo;
import com.apobates.jforum2.troll.utils.core.api.OptionalEntityTransformMapper;
import java.util.Optional;
import java.util.function.Function;

/**
 *
 * @author xiaofanku
 */
public class MemberRecordVoMapperEntity implements OptionalEntityTransformMapper<MemberActiveRecords,MemberRecordVo>{
    @Override
    public Optional<MemberRecordVo> transform(Optional<MemberActiveRecords> entity) {
        return entity.map(mar ->{
            return mapper().apply(mar);
        });
    }

    public static Function<MemberActiveRecords,MemberRecordVo> mapper(){
        return (MemberActiveRecords record)-> {
            MemberRecordVo mrv = new MemberRecordVo();
            mrv.setMember(record.getMemberId());//
            mrv.setDateTime(record.getActiveDateTime());
            mrv.setIp(record.getIpAddr());
            mrv.setDevice(record.getDevice());
            mrv.setAgent(record.getAgent());
            mrv.setIsp(record.getIsp());
            mrv.setProvince(record.getProvince());
            mrv.setCity(record.getCity());
            mrv.setDistrict(record.getDistrict());
            mrv.setAction(record.getAction().getSymbol());
            return mrv;
        };
    }
}